
package Objects;

import GameEngine.GameConstants.Effect;
import GameEngine.GameConstants.Graphic;
import GameEngine.GameConstants.Material;
import GameEngine.GameConstants.Thing;
import GameEngine.LevelInitializer;
import GameEngine.Vector;



/**
 *
 * @author mhfowler
 */
public class Spout extends GameObject {

    // instance variables
    private int spoutPower;
    private boolean isOn = true;


    public Spout(Vector d, Vector cen, Vector s) {
        super(d, cen, s, Graphic.SPOUT);

        material = Material.WALL;
        isTangible = false;

    }


    /* set the strenght of the fan */
    public void setSpoutPower(int strength) {
        spoutPower = strength;
    }

    public int getSpoutPower() {
        return spoutPower;
    }

     /** this method will be called on every object at the beginning of every iteration. In this method
     * particular objects may do specific things, such as arbitrarily update their own attributes based
     * on some correlation to their lifetime (how long they've existed...eg chompers updating their deltaPosition
     * up or down), or even causing an effect on other objects. But every object must iterate through the
     * list of persistent effects on them and receive them.
     */
    @Override
    public void nextIteration() {


        // first apply persistent
        super.applyPersistent();
        if (isOn && lifetime%5 == 0) {
            /* create wind to be direction you face */
            Vector waterSize = new Vector(20, 20);

            Water toCreate = new Water(direction, center, waterSize);
            toCreate.setCurrent(waterSize);
            /* tell parent you created this object */
            lev.createObject(toCreate);
        }


        // then do physics
        super.doPhysics();
        // then undo persitent
        super.cancelPersistent();
    }


    @Override
    public void receiveEffect(Effect e, Vector m, int power) {
        switch (e) {
            case TRANSMUTE:
                isOn = !isOn;
                break;
            case SPEED:
                changed = true;
                spoutPower += power;
                break;
            case SLOW:
                changed = true;
                spoutPower -= power;
                break;
            case CURRENT:
                // do nothing
                break;
            default:
                super.receiveEffect(e, m, power);
                break;
        }
    }
}
